package data

import (
	_ "database/sql"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

type AllInPayRepo struct{}

type AllInPayUserDto struct {
	Id       int    `orm:"pk;auto;column(id)"`
	MemberId int    `orm:"column(member_id)"`
	UserId   string `orm:"column(user_id)"`
}

func init() {
	orm.RegisterModel(new(AllInPayUserDto))
}

func (dto *AllInPayUserDto) TableName() string {
	return "m_allinpay_user"
}

func (repo AllInPayRepo) GetAllInPayUserId(memberId int) (userId string, err error) {
	var dto AllInPayUserDto
	o := orm.NewOrm()
	if err = o.QueryTable("m_allinpay_user").Filter("MemberId", memberId).One(&dto); err == nil {
		userId = dto.UserId
	}
	return
}

func (repo AllInPayRepo) AddAllInPayUser(memberId int, userId string) error {
	o := orm.NewOrm()
	_, err := o.Insert(&AllInPayUserDto{MemberId: memberId, UserId: userId})
	return err
}
